#include <Box2D.h>
#include "common.h"
#include "b2PulleyJointDef.h"

#ifdef __cplusplus
extern "C" {
#endif

JNIEXPORT jdouble JNICALL Java_b2PulleyJointDef_jni_1b2PulleyJointDef_1Initialize1
  (JNIEnv *env, jclass cls,
	jint _groundA, jint _groundB, jint _localA, jint _localB,
	jint _bodyA, jint _bodyB,
	jint _groundAnchorA, jint _groundAnchorB,
	jint _anchorA, jint _anchorB
)
{
	b2Vec2* groundA = (b2Vec2*)_groundA;
	b2Vec2* groundB = (b2Vec2*)_groundB;
	b2Vec2* localA = (b2Vec2*)_localA;
	b2Vec2* localB = (b2Vec2*)_localB;

	b2Body* bodyA = (b2Body*)_bodyA;
	b2Body* bodyB = (b2Body*)_bodyB;

	b2Vec2* groundAnchorA = (b2Vec2*)_groundAnchorA;
	b2Vec2* groundAnchorB = (b2Vec2*)_groundAnchorB;
	b2Vec2* anchorA = (b2Vec2*)_anchorA;
	b2Vec2* anchorB = (b2Vec2*)_anchorB;

	*groundA = *groundAnchorA;
	*groundB = *groundAnchorB;
	*localA = bodyA->GetLocalPoint(*anchorA);
	*localB = bodyB->GetLocalPoint(*anchorB);

	b2Vec2 dA = *anchorA - *groundAnchorA;
	b2Vec2 dB = *anchorB - *groundAnchorB;

	float lengthA = dA.Length();
	float lengthB = dB.Length();
	double value = ( ( (double)lengthA << 32 ) | (double)lengthB );
	return value;
}

#ifdef __cplusplus
}
#endif
